package com.asset.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asset.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.asset.common.annotation.Log;
import com.asset.common.core.controller.BaseController;
import com.asset.common.enums.BusinessType;
import com.asset.manage.domain.Info;
import com.asset.manage.service.IInfoService;
import com.asset.common.utils.poi.ExcelUtil;

/**
 * 资产入库Controller
 *
 * @author mobin
 * @date 2024-08-26
 */
@Api(tags = "资产入库")
@RestController
@RequestMapping("/manage/info")
public class InfoController extends BaseController {
    @Autowired
    private IInfoService infoService;

    /**
     * 查询资产入库列表
     */
    @ApiOperation("查询资产入库列表")
    @PreAuthorize("@ss.hasPermi('manage:info:list')")
    @GetMapping("/list")
    public R<List<Info>> list(Info info) {
        startPage();
        List<Info> list = infoService.selectInfoList(info);
        return R.ok(list);
    }

    /**
     * 导出资产入库列表
     */
    @ApiOperation("导出资产入库列表")
    @PreAuthorize("@ss.hasPermi('manage:info:export')")
    @Log(title = "资产入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Info info) {
        List<Info> list = infoService.selectInfoList(info);
        ExcelUtil<Info> util = new ExcelUtil<Info>(Info.class);
        util.exportExcel(response, list, "资产入库数据");
    }

    /**
     * 获取资产入库详细信息
     */
    @ApiOperation("获取资产入库详细信息")
    @PreAuthorize("@ss.hasPermi('manage:info:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return R.ok(infoService.selectInfoById(id));
    }

    /**
     * 新增资产入库
     */
    @ApiOperation("新增资产入库")
    @PreAuthorize("@ss.hasPermi('manage:info:add')")
    @Log(title = "资产入库", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody Info info) {
        return R.ok(infoService.insertInfo(info));
    }

    /**
     * 修改资产入库
     */
    @ApiOperation("修改资产入库")
    @PreAuthorize("@ss.hasPermi('manage:info:edit')")
    @Log(title = "资产入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody Info info) {
        return R.ok(infoService.updateInfo(info));
    }

    /**
     * 删除资产入库
     */
    @ApiOperation("删除资产入库")
    @PreAuthorize("@ss.hasPermi('manage:info:remove')")
    @Log(title = "资产入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return R.ok(infoService.deleteInfoByIds(ids));
    }
}
